-
Notifications
You must be signed in to change notification settings - Fork 0
Git Commands
Clone a Repo
git Clone <URL> (gets master)
Status of the current branch
git Status
- Tells you the current branch name and files modified.
Create new branch
git Checkout -b <BranchName>
- This will create a new branch and switches to the new branch
Switch to an existing branch
git checkout <BranchName>
Fetching a new branch created by someone else
git fetch
- This will download all the meta data information about the branches existed at the remote (Git Hub)
git checkout <new branch name created by someone else>
- You will be switched to the branch.
Add (un-tracked)changes to the staging area
git add *
- This will add the un-tracked files to the staging area (files you can commit)
Commit your changes to local repository
git commit -m "message"
Create a branch in GitHub you just created locally
git push -u origin demo-branch
- This creates a demo-branch in GitHub
Push code to GitHub remote branch
git push origin demo-branch
- This assumes 'demo-branch' already exists in GitHub and pushes your changes to that branch.
Merge code from a branch
git pull origin master
- Gets latest from master and merges into the branch whatever you are currently in
- This command is more like Get latest in TFS before you check-in your code(before you push your code to GitHub)
Undo modified file changes (which are not added to staging area)
-
git checkout <filename>
-
git status
- should remove the file we 'undo' in the above step 1
undo all files
git checkout .
- This will undo all files you modified and which are not added to staging area.
List of local branches
git branch -l
List of remote repo's that your local git aware of
git branch -r
Delete a local branch
git branch -d <branch name>