Git for beginners by me
Set git user info (assuming that you are the only user of this System)
|
|
User info for a certain Repository only
|
|
Initialize git before using git commands
|
|
Add files on staging area to be committed/Save
|
|
See current git status
|
|
Unstages file(s) from staging area
|
|
Untrack a file/directory permanently from git
|
|
Untrack a file/directory temporarily from git
|
|
Track files which were set to Untrack temporarily in git
|
|
see the list of files set to Untrack temporarily in git
|
|
git ls-files -v |? {$_ -cmatch '^h '}
//Windows friendly
Restore deleted file(s) or reverse the Change in file to last commit.
git restore <file_name> OR
. (Note that files to be restored should have been commited)
Create a Branch
|
|
Visit/Enter a Branch
|
|
Visit a commit from logs
|
|
See logs of the branch
|
|
To checkout the branch when creating it, use
|
|
Note:- if you created a branch and committed some changes you can’t directly push it to remote, first you have to publish it and also set git to auto track it so you can use git push
git pull
directly.
git push -u origin <branch>
(-u is short for –set-upstream)
Note:- You can only create a single PR from a same branch. For how to create more PR for the same repository if your previous PRs are still not merged click-here.
Merge branch
|
|
Delete a Branch
git branch -d <name_of_branch>
(it’ll only work if branch to be deleted is already merged with master branch)
Force delete a Branch
git branch -D <name_of_branch>
(It’ll give error if you are in the branch while deleting it)
See all the files on staged area.
|
|
See git index
|
|
see only modified files
|
|
Stage only modified files
|
|
Commit only modified files
|
|
See status of only tracking files in git
|
|
In case of multiple SSH Github account keys check which one is being used by default
|
|
-
For using multiple SSH keys associated with different github account
Create a ~/.ssh/config file
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Host college.github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_ed25519_harshal24ai017 Host github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_ed25519_harshalrathore2014 Host ec2-13-234-110-107.ap-south-1.compute.amazonaws.com HostName ec2-13-234-110-107.ap-south-1.compute.amazonaws.com IdentityFile ~/harshal/newkeypair.pem User ec2-user
So when you want to Clone college id repo replace git@github.com…. to git@college.github.com… and everything will work like same. pushing will not give error
Git Cheat Sheet