Git Commands.
Git Commands
This is a complete list of commands which you will need to keep in mind. While using git.
git confing --global user.name anant = For setting name for first time
git confing --global user.email xyz@gmail.com = For setting Email.
git config --global user.name = For getting name
git config --global user.email = For getting email
git init = For making the git repository at that directory.
git add --a OR git add -A = For adding all untracked files to work stage
git commit -m "Second commit new features added" = for committing the stage files repository.
git status = For looking untracked files or not committed files on repository.
git log = For looking all history commit's.
rm -rf .git = For deleting all info about that repository which were in .git folder.
ls = For looking all files in present working directory.
pwd = For looking present working directory.
git clone [Link of a repository from github] = For cloning means to download a copy from github to your pwd.
cd [directory path] = For changing the pwd.
touch python.py = Touch command for creating any time of file.
touch .gitignore = Creating a file for storing the names of files and folders to be ignored.
***Git doesn't track empty folders***
**Can also give full path of a directory to ignore in .gitignore file**
git diff = It compares Staging area with working directory.
git diff --staged = It compares Staging area files with recent commit made.
git restore [file name] = To discard changes in working directory.
git commit -a -m "A Direct commit" = For skipping staging area while committing of modified files.
git rm [file name] = For deleting a file from pwd.
git mv [before file name] [after file name] = To rename a file in pwd.
***mv stands for moving first file to new file name in linux.***
git rm --cached [file name] = To untrack a tracked file.
***And put name's of untracked files in .gitignore for not having any error of untrack of that perticular file***
**Git log commands**
git log -p = For viewing log with difference made by that commit.
git log -p -n = n refers to value of recents commits to show with their changes made.
git log --stat = Shows a summary of changes made in recents commit.
git log --pretty=oneline = Show commits in one line.
git log --pretty=short = For displaying commits in short.
git log --pretty=full = For displaying commits fully with commit message.
git log --since=2.days = For displaying commits of recent 2 days.
git log --since=3.months = For displaying commits of recent 3 months.
git log --since=2.weeks
git log --since=2.years
git log --pretty=oneline --since=2.years = Having two filters at a time. Commits of recent two years and in one line.
git log --pretty=oneline --since=2.days = Will show recent 2 days commits in one line.
git commit --amend = For adding some changes to your recent 1 commit.
*For this first do that change and then put that file changed in to staging area and then just run the above command*
***For Using vim editor after running the --amend command first press i for typing the message of commit then esc then : then wq and press enter the changes will be saved***
git log --pretty=format: "%h -- %an" = For looking log in the format which you want.
git restore --staged text.txt = To unstage a file.
git restore --staged anant.py = For unstaging that file and moving it to modified stage.
*For looking more types of formats which you can make with above command check out documentation for Git-log -- Link *
git remote = shows remote's available
git remote add origin git@github.com:AnantLuthra/repositoryname.git = This add a remote origin
git remote -v = Shows URL (Pull, Push)
*Setting up Git with Github*
ssh-keygen -t ed25519 -C "your@gmail.com" = Setting up git with hosting website github
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
tail ~/.ssh/id_ed25519.pub
git push -u origin master = push means to send your depository's master branch to website.
*All commands related to SSH key is here = Link*
git config --global alias.[shortcut name] 'real command' = For making shortcut's of commands with the help of alias
git checkout -b develop = For creating and switching to a new branch.
git checkout master = To switch to back master branch.
git checkout developing = put name after checkout for switching to that branch.
git branch = For displaying all branches made.
***Always leave tree clean before switching to another branch***
git merge (other branch name) = It is command to merge other branch with master branch
*Use this command after switching in master command*
*Then go in vs code for choosing the option "Accept Incoming change"*
**Deleting branches**
git branch -v = It shows all branch's last commit.
git branch --merged = It print the name of branches which are merged somewhere before.
git branch --no-merged = Not merged yet with any branch.
git branch -d develop = Delete's the branch. Gives error if develop branch is not merged with any branch yet.
git branch -D develop = Gives no error and branch get's deleted.
**Pushing branches**
***You should be in the branch which you are pushing***
git push origin master = Will push master branch to origin.
git push origin bugfix:NewBugFix = Pushing a branch with different name in github putting : after the branch name and put a new branch.
git push -d origin MyBugfix = This will delete branch from our github server.
Now it's done....
Comments
Post a Comment