1. Open Git bash
Download existing source from Sever(Github/Gitlab):
1. cd path_of_the_workspace
2. git clone url_of_repo_on_github/gitlab name_of_the_local_folder
Eg: git clone https://github.com/naveenanem22/pmt-phase1.git demo
Note: Name of the localfolder is optional. If not provided, it will create a same name as per the repo on server
The above command will create a folder with the name of the root folder of the project on server inside the workspace directory
a remote called 'origin' gets created with the url of the remote-project-on-the-server
The local project folder gets initialised with git init command
3. cd name_of_project_folder
eg: cd pmt-phase1
4. Clone a branch of a repo..not the master
git clone --single-branch
as in:
git clone --branch --single-branch []
git clone https://NKumar@www.servername.com./scm/reponame/someapp.git --branch v3-update --single-branch
Following commands are valid from the project folder on the local machine:
cd name_of_prj_flder
1)git branch: Shows the details of all the branches the local project has
2) git remote: show the details of the remotes the project connected to
What is remote?
Remote is the alias of the url from where branch is created
A project can have as many remotes as possible
A branch can update its source from any of the remote
3) git init: This is the first command to bring a project(folder) under the radar of Git.
Execute this command from project-root-folder.
4a) git add . : commits all the files from working-dir to staging-area
4b) git add "name_of_the_file.ext" : adds specific file from working-dir to staging-area
eg: git add tobeaddedfile.txt
5) git commit: commits all the changes from staging-area to repo
eg: To commit all files => git commit -m "This is the commit comment"
To commit specific file => git commit "name_of_the_file.ext" -m "comment"
eg: git commit system.js -m "Committing system.js"
6) git push: pushes local dir to server
7) git status: shows the details of the git local project
8) Rename a remote:
git remote rename old_name new_name
eg: git remote rename old_name new_name
9) Rename the current branch to a new name
Eg: git branch -m new_branch_name
9) Switch to another branch
10) To discard changes done to a file
eg: git checkout -- name_of_thefile.java
11. How to remove a project-root folder from Git Version system if it is initiated by 'git init' command
Navigate to project-root folder in windows explorer-> Show Hidden files -> Delete .git folder. This should remove the project-root from Git system. Use git init command to add it again.
12. git branch -a
Lists all the branches local and remote
13. git commit history with timestamp
git log --pretty=format:"%ad %h by %an, %s" --date=iso | sort -r | less
14.To reset to a previous commit
git reset --hard
15. To delete a branch
git branch -d
16. To revert a particular commit
git revert <#commit-hash>
eg: git revert 00eer6549
17. To rebase a branch1 from branch2
Step 1: Switch to the branch1
git checkout branch1
Step 2: git rebase origin/branch2
Step 3: git status --> This will show you to pull the changes..but don't do that..rather issue the following command..
git push -f -> this is to force push the changes
Following are useful linux(unix) commands:
1. ls --> lists all the subfiles and folder under a specific directory
2. ls -la --> lists all sub files and fodlers including hidden and meta files
Create a branch from master branch in local
Note: Before creating a new branch, always uptodate the current branch
1. cd name_of_prj_flder
2. git checkout -b new_branch_name
eg: git checkout -b pmtnaveen
Once work changes committed to local repo, push the branch to server.
3. add all files to staging area
git add .
4. commit files from staging to final-repo
git commit -m "This is the commit comment"
5. git push remote_name branch_name or git push --set-upstream remote_name branch_name
a new branch gets created on the server(github)
How to add a local project to git version control and eventually create a repo on server
1. from Git bash: cd to Project_root folder
2. git init
Desc: this adds the whole project folder into git version control
3. git add .
Desc: to add all files and folders under the project to staging area
4. git commit -m "comment"
Desc: to commit the files from staging to commit
4.a git commit
Desc: To commit the files and write the comments on the editor. ':wq' to exit
5. Create a 'repo' on github and copy the url
6. create remote pointing to the step-5's url
git remote add 'name_of_the_remote' 'url_of_the_remote_git_repo.git'
eg: git remote add origin https://github.com/naveenanem22/meandemo.git
7. git push 'name_of_the_remote' 'name_of_the_branch'
git push origin master
Update localbranch to track remote branch:
cd name_of_prj_folder
1. git branch -u remote_name/branch_name
2. git pull
Git editor shortcut keys:
1. press "i"
2. write your merge message
3. press "esc"
4. write ":wq"
then press enter
Gitignore:
How to tell git to ignore some files/folders from tracking
Ans:
1. Add a file called '.gitignore' in project root dir.
2. Specify the names of the files or folders or with pattern in .gitignore file. Save the file.
3. Add the file to git system by git add command
4. Then commit .gitignore file
5. Run git status command to check if the ignored files shown under untracked are not visible anymore
Download existing source from Sever(Github/Gitlab):
1. cd path_of_the_workspace
2. git clone url_of_repo_on_github/gitlab name_of_the_local_folder
Eg: git clone https://github.com/naveenanem22/pmt-phase1.git demo
Note: Name of the localfolder is optional. If not provided, it will create a same name as per the repo on server
The above command will create a folder with the name of the root folder of the project on server inside the workspace directory
a remote called 'origin' gets created with the url of the remote-project-on-the-server
The local project folder gets initialised with git init command
3. cd name_of_project_folder
eg: cd pmt-phase1
4. Clone a branch of a repo..not the master
git clone --single-branch
as in:
git clone
git clone https://NKumar@www.servername.com./scm/reponame/someapp.git --branch v3-update --single-branch
Following commands are valid from the project folder on the local machine:
1)git branch: Shows the details of all the branches the local project has
2) git remote: show the details of the remotes the project connected to
What is remote?
Remote is the alias of the url from where branch is created
A project can have as many remotes as possible
A branch can update its source from any of the remote
3) git init: This is the first command to bring a project(folder) under the radar of Git.
Execute this command from project-root-folder.
4a) git add . : commits all the files from working-dir to staging-area
4b) git add "name_of_the_file.ext" : adds specific file from working-dir to staging-area
eg: git add tobeaddedfile.txt
5) git commit: commits all the changes from staging-area to repo
eg: To commit all files => git commit -m "This is the commit comment"
To commit specific file => git commit "name_of_the_file.ext" -m "comment"
eg: git commit system.js -m "Committing system.js"
6) git push: pushes local dir to server
7) git status: shows the details of the git local project
8) Rename a remote:
git remote rename old_name new_name
eg: git remote rename old_name new_name
9) Rename the current branch to a new name
Eg: git branch -m new_branch_name
9) Switch to another branch
10) To discard changes done to a file
eg: git checkout -- name_of_thefile.java
11. How to remove a project-root folder from Git Version system if it is initiated by 'git init' command
Navigate to project-root folder in windows explorer-> Show Hidden files -> Delete .git folder. This should remove the project-root from Git system. Use git init command to add it again.
12. git branch -a
Lists all the branches local and remote
13. git commit history with timestamp
git log --pretty=format:"%ad %h by %an, %s" --date=iso | sort -r | less
14.To reset to a previous commit
git reset --hard
15. To delete a branch
git branch -d
16. To revert a particular commit
git revert <#commit-hash>
eg: git revert 00eer6549
17. To rebase a branch1 from branch2
Step 1: Switch to the branch1
git checkout branch1
Step 2: git rebase origin/branch2
Step 3: git status --> This will show you to pull the changes..but don't do that..rather issue the following command..
git push -f -> this is to force push the changes
Following are useful linux(unix) commands:
1. ls --> lists all the subfiles and folder under a specific directory
2. ls -la --> lists all sub files and fodlers including hidden and meta files
Create a branch from master branch in local
Note: Before creating a new branch, always uptodate the current branch
1. cd name_of_prj_flder
2. git checkout -b new_branch_name
eg: git checkout -b pmtnaveen
Once work changes committed to local repo, push the branch to server.
3. add all files to staging area
git add .
4. commit files from staging to final-repo
git commit -m "This is the commit comment"
5. git push remote_name branch_name or git push --set-upstream remote_name branch_name
a new branch gets created on the server(github)
How to add a local project to git version control and eventually create a repo on server
1. from Git bash: cd to Project_root folder
2. git init
Desc: this adds the whole project folder into git version control
3. git add .
Desc: to add all files and folders under the project to staging area
4. git commit -m "comment"
Desc: to commit the files from staging to commit
4.a git commit
Desc: To commit the files and write the comments on the editor. ':wq' to exit
5. Create a 'repo' on github and copy the url
6. create remote pointing to the step-5's url
git remote add 'name_of_the_remote' 'url_of_the_remote_git_repo.git'
eg: git remote add origin https://github.com/naveenanem22/meandemo.git
7. git push 'name_of_the_remote' 'name_of_the_branch'
git push origin master
Update localbranch to track remote branch:
cd name_of_prj_folder
1. git branch -u remote_name/branch_name
2. git pull
Git editor shortcut keys:
1. press "i"
2. write your merge message
3. press "esc"
4. write ":wq"
then press enter
Gitignore:
How to tell git to ignore some files/folders from tracking
Ans:
1. Add a file called '.gitignore' in project root dir.
2. Specify the names of the files or folders or with pattern in .gitignore file. Save the file.
3. Add the file to git system by git add command
4. Then commit .gitignore file
5. Run git status command to check if the ignored files shown under untracked are not visible anymore
No comments:
Post a Comment