Do I really need to know how to use git?[SOLVED]

That isn’t something for beginners though: that’s Git Flow, it’s for large projects with multiple developers, and it’s a massive pain in the ass to get right (involves widespread use of git rebase, which is not something you want to be dealing with as a beginner [or imo, ever]). It exists to provide multiple levels of redundancy and safety for teams where multiple developers are working on separate features for projects at the same time. It’s not necessary if you’re a beginner with Git; it doesn’t make anything easier, makes small projects much more complex, and adds a lot of ceremony

Those are a lot of good resources everyone. I made this for myself when I was learning - perhaps it can be helpful to someone else. Feel free correct any mistakes if I made any. Or if anyone wants to suggest additions or changes.

How to use github command line

Useful commands:

		git --help
		git --version
		git init (initialize repo locally)
		git add <filename> (adds <filename> to staging)
		git status (shows current status)
		git diff (shows changes since last commit)
		git commit -m "<message>"
		git push <remote> <branch> 
		git config --global user.name "<Your Name>" (changes config file)
		git config --global user.email "<youremail@example.com>" (changes config file)
		git remote add origin "<URL HERE>" (for adding a new remote)
		git remote set-url origin <URL from github.com repo> (for setting the remote)
		git remote -v (verifies the remote URL)
		git branch <branch name> (creates a new branch)
		git checkout <branch name> (work with branch name)
		git pull <remote> <branch> (merges any changes to your local repo)
		git branch -d <branch> (delete a branch)
		touch .gitignore (create .gitignore file)
		echo '<filename>' >> .gitignore (to add folders or files to the .gitignore file)

		git fetch --all (This will pull from origin repo)
                git reset --hard <remote>/<branch_name> (this will overwrite all local changes)
		 --for explanation see https://forum.freecodecamp.org/t/override-local-files-with-git-pull/13216/2


How to create a repo locally and push it to github:

	Step 1: git init (use in a folder to initialize a repo locally)
	Step 2:	git add <filename> (add <filename> to staging area for next commit)
		or 	git add . (adds all files to staging)
	Step 3:	git commit -m "<message>" (commits files in staging)
	Step 4:	go to the github website and create a repo
	Step 5:	get the 'cloning' url from the quick setup area by copying the url 
		or	get the 'cloning' url by click the green 'clone or download' button in the repo and copy the url
	Step 6:	git remote add origin <URL from github> 
				(get the url after creating repo, and next page copy the url - origin = remote name so we know what repo to commit to)
	Step 7:	git push origin master (origin=remote master=branch)


How to fork a repo and pull it from github:
	Step 1:	go to a repo you want to fork and click the fork button at the top right
				(this will fork it to your account)
	Step 2:	go to your account/newly forked repo and click the green 'clone or download' button and the copy URL button
	Step 3:	git clone <URL you copied from step 2>
				(now its copied to your computer and linked to the forked repo on your account)
	Step 4:	copy the URL from the original repo you forked by going to the repo and clicking the green 'clone or download' button and the copy button
	Step 5:	git remote add upstream <URL you copied from step 4>
				(this adds a remote to the original repo to pull in changes made there)
				(you can name this remote connection anything you want - people often use 'upstream')


If you have pushed changes to a branch, you will want to make a pull request to get your changes merged with the original repo:
	Step 1:	go to your repo and click create pull request
	Step 2:	fill in the info and make the request


After your changes are merged with the original repo, you want to merge that repo with your forked one again:
	Step 1: git checkout <branch of original repo>
				(work with the branch you want to merge 'into')
	Step 2: git merge <branch>
				(tell git what bring you want to merge 'in')
	Step 3:	git branch -d <branch>
				(clean up by deleting the old branch no longer needed since it has been merged to the original)
	Step 4:	git push <remote> --delete <branch>
				(delete the branch on your fork)			


Maintaining Your Fork
Now that you have a copy of your fork, there is work you will need to do to keep it current.
Rebasing from Upstream

Do this prior to every time you create a branch for a PR:
//This is specific for the freecodecamp repo - replace staging with whatever branch youre working with - and upstream with another remote if you have one

 -  Make sure you are on the staging branch
    $ git status
    On branch staging
    Your branch is up-to-date with 'origin/staging'.

 -  If your arent on staging, resolve outstanding files / commits and checkout the staging branch
    $ git checkout staging

 -  Do a pull with rebase against upstream
    $ git pull --rebase upstream staging

 -  This will pull down all of the changes to the official staging branch, without making an additional commit in your local repo.
    (Optional) Force push your updated staging branch to your GitHub fork
    $ git push origin staging --force
    This will overwrite the staging branch of your fork.

Check this URL for a visual on github repos 
	https://guides.github.com/introduction/flow/

Created from the 'git-it' workshop 
Check out the lessons here: http://jlord.us/git-it/
5 Likes

A basic knowledge of Git is pretty much essential to a professional developer, although I think that understanding what git is and how it works is much more important than knowing the commands. I actually avoid using the command line and instead use a GUI, it allows me to visualize everything that is going on much better. If you are interested, I use Tower:

https://www.git-tower.com/mac/

Also - this is an earlier thread on this topic that has lots of helpful information - I don't understand Git and GitHub

If you have no experience with using version control systems or you used SVN before, take a look at this blog post which briefly discusses the most important features of Git that you need to know at the beginning.

1 Like