Commands Flashcards
Configure your username and email
git config –global user.name “Your name”
git config –global user.email “yourname@provider.com”
View git configurations
git config –list
How to initialize a repository
Create a folder and repository on GitHub and open the folder in the Terminal and use the command “git init”
instruct Git to link it with the remote repository
git remote add origin repo-url
If your remote repository already contains some code files, then you need to pull them inside your local repository
git pull
git init + git remote add origin repo-url + git pull
git clone repo-url [folder]
verify if a local repository is tracking the remote repository
git remote -v
replace the remote url
git remote set-url origin repo-url
This file contains files and folder names that should be ignored by Git while making commits.
.gitignore
move these files to the staging area
git add . || git add [filename] || git add -A || git add *
If you added some files in the staging area by mistake, then you can use the following command to unstage them
git reset [filename]
To create a commit, use the following command.
git commit -m “initial commit”
flag is used to insert a message that will describe the commit.
-m
All files shows _____ mode which means there are all new file.
create
To see all the commits in the repository (made by all the developers), use following command.
git log
To see file that was changed or added in a commit
git log –stat
To change the message of the previous commit
git commit –amend -m “Initial Commit”
You can avoid edit message dialog
git commit –amend –no-edit
to write and exit the vim editor
ESC + :wq
push that commit to the remote repository.
git push -u origin master
forget if commits after that ever existed
git reset –soft #
git reset –mixed #
git reset –hard #
You can use git ____ to see what code changes between the current state of the files and the state of the files in the previous commit.
diff
will set state of the above file to state of file in HEAD commit
git checkout – [filename]
If you have lots of untracked files or folders in the repository which you want to remove
git clean -f -d
create a branch with the name
git branch
git branch [name]
git checkout [branch name]
To check all local and remote branches
git branch -a
to update your remote-tracking branches
git fetch
If a remote branch already exists with a different name than you want to track with the current branch, then use command
git branch –set-upstream-to origin/dev_uday
command will create [branch name] branch on remote repository and our local branch will track it
git push -u origin [branch name]
switch to master [Head]
git checkout master
we must pull code from the remote repository before doing anything, always do this.
git pull
git branch –merged
following command will merge the branch with the current branch.
git merge [branch name]
verify merger by executing
git branch –merged
If we are done with branch and we don’t need it anymore, then we can just delete it using the command below. This will delete local branch only.
git branch -d [branch name]
To delete remote dev branch as well, you need to use the command
git push –delete origin [branch name]